#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QPushButton>
#include <Widget.h>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 查看windowFrame对geometry属性的影响
    QRect rect1 = this->geometry();
    QRect rect2 = this->frameGeometry();
    qDebug() << "this->geometry():      " << rect1;
    qDebug() << "this->frameGeometry(): " << rect2;

    /*
     * 结果:在构造函数中看不到影响,因为对象还在构建,并没有被挂到对象树
    09:33:34: Starting D:\Remote repositories\qt-code\QWidget_5\build\Desktop_Qt_5_15_2_MinGW_64_bit-Debug\debug\QWidget_5.exe...
    QRect(0,0 800x600)
    QRect(0,0 800x600)
    09:33:39: D:\Remote repositories\qt-code\QWidget_5\build\Desktop_Qt_5_15_2_MinGW_64_bit-Debug\debug\QWidget_5.exe 退出，退出代码: 0
    {1 ?} {2?}
    */

    // 设置当点击按钮再执行代码
    QPushButton *button = new QPushButton(this);
    button ->setText("按钮");
    button ->move(100, 100);
    connect(button, &QPushButton::clicked, this, &Widget::handleClicked);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::handleClicked()
{
    // 查看windowFrame对geometry属性的影响
    QRect rect1 = this->geometry();
    QRect rect2 = this->frameGeometry();
    qDebug() << "this->geometry():     " << rect1;
    qDebug() << "this->frameGeometry(): " << rect2;

    /*
    09:42:12: Starting D:\Remote repositories\qt-code\QWidget_5\build\Desktop_Qt_5_15_2_MinGW_64_bit-Debug\debug\QWidget_5.exe...
    this->geometry():       QRect(0,0 800x600)
    this->frameGeometry():  QRect(0,0 800x600)
    this->geometry():      QRect(880,384 800x600)
    this->frameGeometry():  QRect(879,339 802x646)
    09:42:18: D:\Remote repositories\qt-code\QWidget_5\build\Desktop_Qt_5_15_2_MinGW_64_bit-Debug\debug\QWidget_5.exe 退出，退出代码: 0
    {1 ?} {2?}
    */
}
